package com.example.orderfood2;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.InputType;
import android.widget.EditText;
import android.widget.Toast;

import com.example.orderfood2.DatabaseManager.DatabaseManager;
import com.example.orderfood2.Repository.StudentRepository;
import com.example.orderfood2.util.DBUtil;
import com.example.orderfood2.util.ToolsUtil;

public class PasswordChangeDialogStudent {
//    private DBUtil dbUtil;
    public static void showPasswordChangeDialogStudent(Context context,String account){
        StudentRepository dbUtil= DatabaseManager.getInstance(new StudentActivity()).getStudentRepository();
        AlertDialog.Builder builder=new AlertDialog.Builder(context);
        builder.setTitle("修改密码");        //创建一个输入框
        final EditText input=new EditText(context);
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        builder.setView(input);
        //设置确认按钮
        builder.setPositiveButton("确认修改", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
//                DBUtil dbUtil = new DBUtil(context);
                int PasswordChangeDialogStudent=dbUtil.StudentChangePassword(account, ToolsUtil.editTextToString(input));
                Toast.makeText(context,"修改成功",Toast.LENGTH_SHORT).show();
            }
        });
        //设置取消按钮
        builder.setNegativeButton("取消修改", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.cancel();
            }
        });
        //显示AlertDialog
        builder.show();
    }
}
